package com.csproj.system.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * 权限表
 */
@Entity
@Table(name = "sys_authority_info")
@EntityListeners(AuditingEntityListener.class)
public class AuthorityInfo implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @Column(name = "id")
    private String id;

    @Column(name = "code")
    private String code;            //编号

    @Column(name = "parent_code")
    private String parentCode;      //父级编号

//    private String href;            //链接地址
    @Column(name = "name")
    private String name;            //菜单名称

    @Column(name = "permission")
    private String permission;      //权限标识

    @Column(name = "target")
    private String target;          //目标（mainFrame、 _blank、_self、_parent、_top）

    @Column(name = "is_show")
    private Boolean isShow;         //菜单是否显示(1 显示 0 不显示)

    @Column(name = "sort")
    private Integer sort;           //排序（升序）

    @Column(name = "remark")
    private String remark;          //备注

    @Column(name = "deleted_flag")
    private Boolean deletedFlag;

    @ManyToMany(mappedBy = "authorityInfos")
    @JsonIgnore
    private Set<RoleInfo> roleInfos = new HashSet<>();


    public Set<RoleInfo> getRoleInfos() {
        return roleInfos;
    }

    public AuthorityInfo roleInfos(Set<RoleInfo> roleInfos) {
        this.roleInfos = roleInfos;
        return this;
    }

    public AuthorityInfo addRoleInfo(RoleInfo roleInfo) {
        this.roleInfos.add(roleInfo);
        roleInfo.getAuthorityInfos().add(this);
        return this;
    }

    public AuthorityInfo removeRoleInfo(RoleInfo roleInfo) {
        this.roleInfos.remove(roleInfo);
        roleInfo.getAuthorityInfos().remove(this);
        return this;
    }

    public void setRoleInfos(Set<RoleInfo> roleInfos) {
        this.roleInfos = roleInfos;
    }
    /**
     * 删除人
     */
    @ApiModelProperty(value = "删除人")
    @Column(name = "deleter_user_id")
    private String deleterUserId;

    /**
     * 删除时间
     */
    @ApiModelProperty(value = "删除时间")
    @Column(name = "deletion_time")
    private ZonedDateTime deletionTime;

    /**
     * 最近更新时间
     */
    @LastModifiedDate
    @ApiModelProperty(value = "最近更新时间")
    @Column(name = "last_modification_time")
    private ZonedDateTime lastModificationTime;

    /**
     * 最近更新人
     */
    @LastModifiedBy
    @ApiModelProperty(value = "最近更新人")
    @Column(name = "last_modifier_user_id")
    private String lastModifierUserId;

    /**
     * 创建时间
     */
    @CreatedDate
    @ApiModelProperty(value = "创建时间")
    @Column(name = "creation_time")
    private ZonedDateTime creationTime;

    /**
     * 创建人
     */
    @CreatedBy
    @ApiModelProperty(value = "创建人")
    @Column(name = "creator_user_id")
    private String creatorUserId;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getParentCode() {
        return parentCode;
    }

    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public Boolean getShow() {
        return isShow;
    }

    public void setShow(Boolean show) {
        isShow = show;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Boolean getDeletedFlag() {
        return deletedFlag;
    }

    public void setDeletedFlag(Boolean deletedFlag) {
        this.deletedFlag = deletedFlag;
    }

    public String getDeleterUserId() {
        return deleterUserId;
    }

    public void setDeleterUserId(String deleterUserId) {
        this.deleterUserId = deleterUserId;
    }

    public ZonedDateTime getDeletionTime() {
        return deletionTime;
    }

    public void setDeletionTime(ZonedDateTime deletionTime) {
        this.deletionTime = deletionTime;
    }

    public ZonedDateTime getLastModificationTime() {
        return lastModificationTime;
    }

    public void setLastModificationTime(ZonedDateTime lastModificationTime) {
        this.lastModificationTime = lastModificationTime;
    }

    public String getLastModifierUserId() {
        return lastModifierUserId;
    }

    public void setLastModifierUserId(String lastModifierUserId) {
        this.lastModifierUserId = lastModifierUserId;
    }

    public ZonedDateTime getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(ZonedDateTime creationTime) {
        this.creationTime = creationTime;
    }

    public String getCreatorUserId() {
        return creatorUserId;
    }

    public void setCreatorUserId(String creatorUserId) {
        this.creatorUserId = creatorUserId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AuthorityInfo that = (AuthorityInfo) o;
        return Objects.equals(id, that.id) &&
                Objects.equals(code, that.code) &&
                Objects.equals(parentCode, that.parentCode) &&
                Objects.equals(name, that.name) &&
                Objects.equals(permission, that.permission) &&
                Objects.equals(target, that.target) &&
                Objects.equals(isShow, that.isShow) &&
                Objects.equals(sort, that.sort) &&
                Objects.equals(remark, that.remark) &&
                Objects.equals(deletedFlag, that.deletedFlag) &&
                Objects.equals(deleterUserId, that.deleterUserId) &&
                Objects.equals(deletionTime, that.deletionTime) &&
                Objects.equals(lastModificationTime, that.lastModificationTime) &&
                Objects.equals(lastModifierUserId, that.lastModifierUserId) &&
                Objects.equals(creationTime, that.creationTime) &&
                Objects.equals(creatorUserId, that.creatorUserId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, code, parentCode, name, permission, target, isShow, sort, remark, deletedFlag, deleterUserId, deletionTime, lastModificationTime, lastModifierUserId, creationTime, creatorUserId);
    }

    @Override
    public String toString() {
        return "AuthorityInfo{" +
                "id='" + id + '\'' +
                ", code='" + code + '\'' +
                ", parentCode='" + parentCode + '\'' +
                ", name='" + name + '\'' +
                ", permission='" + permission + '\'' +
                ", target='" + target + '\'' +
                ", isShow=" + isShow +
                ", sort=" + sort +
                ", remark='" + remark + '\'' +
                ", deletedFlag=" + deletedFlag +
                ", deleterUserId='" + deleterUserId + '\'' +
                ", deletionTime=" + deletionTime +
                ", lastModificationTime=" + lastModificationTime +
                ", lastModifierUserId='" + lastModifierUserId + '\'' +
                ", creationTime=" + creationTime +
                ", creatorUserId='" + creatorUserId + '\'' +
                '}';
    }
}
